<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // 1.创建promise对象(pending-待定状态)
        const p = new Promise((resolve,reject)=>{
            // 2.执行异步代码
            setTimeout(()=>{
                // resolve()=>'fulfilled状态-已兑现'
                resolve('成功')
                // reject()=>'rejected状态-已拒绝'
                reject(new Error('失败'))
            },2000)
        })
        // 3.获取结果
        p.then(result=>{
            console.log(result)
        }).catch(error=>{
            console.log(error)
        })
    </script>
</body>
</html>